package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import bean.UserBean;

public class LoginDao {
	public boolean checkLogin(String name, String password, UserBean user) throws ClassNotFoundException, SQLException {
		Connection conn = DBUtil.getConnection();
		PreparedStatement ps = conn.prepareStatement("select * from user where username=? and userpassword=?");
		ps.setString(1, name);
		ps.setString(2, password);
		ResultSet result = ps.executeQuery();
		boolean res;
		if(result.next()) {
			user.setId(result.getInt(1));
			user.setName(result.getString(2));
			user.setPassword(result.getString(3));
			user.setTelephone(result.getString(4));
			user.setDormitoryId(result.getInt(5));
			res = true;
		}
		else
			res = false;
		ps.close();
		conn.close();
		result.close();
		System.out.println(res);
		return res;
	}
}

